package online.siwu.encodingviewer

import android.annotation.SuppressLint
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.annotation.IntegerRes
import android.view.View
import kotlinx.android.synthetic.main.activity_main.*
import java.net.URLEncoder
import java.nio.charset.Charset
import java.util.*

@SuppressLint("SetTextI18n")
class MainActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


        btEnCoding.setOnClickListener(oclEnCoding)
        etInput.setText("abc123中国")


    }

    private val oclEnCoding = View.OnClickListener {
        val str = etInput.text.toString()
        val bt = str.toByteArray(charset("UTF-8"))

        var str2 = ""
        for (i in bt){
            str2 += Integer.toHexString(i.toInt()).toString().toUpperCase()

    }

        etOutput.setText(str2)
//        toast(bt.toString(charset = Charsets.US_ASCII))
    }


}
